package com.qf.controller;

import com.qf.entity.Medicinei;
import com.qf.entity.Medicineii;
import com.qf.pojo.BaseResult;
import com.qf.serevice.MedicineInfoService;
import com.qf.serevice.MedicineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/medicine")
@CrossOrigin
public class MedicineController {

    @Autowired
    MedicineService medicineService;
    @Autowired
    MedicineInfoService medicineInfoService;

    @RequestMapping(value = "/findAllMedicineInfo",method = RequestMethod.GET)
    public BaseResult findAllMedicineInfo(@RequestParam("page")Integer page, @RequestParam("size")Integer size, @RequestParam("name")String name){
        BaseResult allMedicineInfo = medicineInfoService.findAllMedicineInfo(page,size,name);
        return allMedicineInfo;
    }
    //根据药品类别查找药品
    @RequestMapping(value = "/findByIdMedicine",method = RequestMethod.GET)
    public BaseResult findByIdMedicine(@RequestParam(value="midi") Integer midi){
        BaseResult allMedicine = medicineService.findByIdMedicine(midi);
        return allMedicine;
    }
    //添加新的药品
    @RequestMapping(value = "/addMedicine",method = RequestMethod.POST)
    public BaseResult addMedicine(@RequestBody Medicineii medicineii){
        BaseResult result = medicineService.addMedicine(medicineii);
        return result;
    }
    //修改药品信息
    @RequestMapping(value = "/updateMedicine",method = RequestMethod.PUT)
    public BaseResult updateMedicine(@RequestBody Medicineii medicineii){
        BaseResult result = medicineService.updateMedicine(medicineii);
        return result;
    }
    //删除药品
    @RequestMapping(value = "/deleteMedicineById/{midii}",method = RequestMethod.DELETE)
    public BaseResult deleteMedicineById(@PathVariable("midii") Integer midii){
        BaseResult result = medicineService.deleteMedicineById(midii);
        return result;
    }
}
